package org.dromara.netbar.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.netbar.domain.vo.NetbarGiftPackItemVo;
import org.dromara.netbar.domain.bo.NetbarGiftPackItemBo;
import org.dromara.netbar.service.INetbarGiftPackItemService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 礼包-卡券关联
 *
 * @author Lion Li
 * @date 2025-07-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/netbar/giftPackItem")
public class NetbarGiftPackItemController extends BaseController {

    private final INetbarGiftPackItemService netbarGiftPackItemService;

    /**
     * 查询礼包-卡券关联列表
     */
    @SaCheckPermission("netbar:giftPackItem:list")
    @GetMapping("/list")
    public TableDataInfo<NetbarGiftPackItemVo> list(NetbarGiftPackItemBo bo, PageQuery pageQuery) {
        return netbarGiftPackItemService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出礼包-卡券关联列表
     */
    @SaCheckPermission("netbar:giftPackItem:export")
    @Log(title = "礼包-卡券关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(NetbarGiftPackItemBo bo, HttpServletResponse response) {
        List<NetbarGiftPackItemVo> list = netbarGiftPackItemService.queryList(bo);
        ExcelUtil.exportExcel(list, "礼包-卡券关联", NetbarGiftPackItemVo.class, response);
    }

    /**
     * 获取礼包-卡券关联详细信息
     *
     * @param packItemId 主键
     */
    @SaCheckPermission("netbar:giftPackItem:query")
    @GetMapping("/{packItemId}")
    public R<NetbarGiftPackItemVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long packItemId) {
        return R.ok(netbarGiftPackItemService.queryById(packItemId));
    }

    /**
     * 新增礼包-卡券关联
     */
    @SaCheckPermission("netbar:giftPackItem:add")
    @Log(title = "礼包-卡券关联", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody NetbarGiftPackItemBo bo) {
        return toAjax(netbarGiftPackItemService.insertByBo(bo));
    }

    /**
     * 修改礼包-卡券关联
     */
    @SaCheckPermission("netbar:giftPackItem:edit")
    @Log(title = "礼包-卡券关联", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody NetbarGiftPackItemBo bo) {
        return toAjax(netbarGiftPackItemService.updateByBo(bo));
    }

    /**
     * 删除礼包-卡券关联
     *
     * @param packItemIds 主键串
     */
    @SaCheckPermission("netbar:giftPackItem:remove")
    @Log(title = "礼包-卡券关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{packItemIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] packItemIds) {
        return toAjax(netbarGiftPackItemService.deleteWithValidByIds(List.of(packItemIds), true));
    }
}
